package org.test.springAOP.baseAnnotation;

import java.util.Calendar;

import org.apache.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Repository;

@Aspect
@Repository("TheAspect")
public class TheAspect {
	
	private Logger log = Logger.getLogger(this.getClass());

//	/**
//	 * 方法前
//	 */
//	@Before("execution(* org.test.springAOP.baseAnnotation.TargetClass.save(String,String))")
//	public void before() {
//		System.out.println("beforeMethod");
//	}
//	/**
//	 * 
//	 */
//	@AfterReturning("execution(* org.test.springAOP.baseAnnotation.TargetClass.save(String,String))")
//	public void afterReturn() {
//		System.out.println("afterReturn");
//	}
//	
	@Around("execution(* org.test.springAOP.baseAnnotation.TargetClass.save(String,String))")
	public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
		Object[] args = joinPoint.getArgs();
		Calendar beginCalendar = Calendar.getInstance();
		Object obj = joinPoint.proceed(args);
		 Calendar endCalendar = Calendar.getInstance();
		 long m = endCalendar.getTimeInMillis()- beginCalendar.getTimeInMillis();
		 String methodName = joinPoint.getSignature().getName();// 调用方法
		 String className = joinPoint.getTarget().getClass().getCanonicalName();
		 log.debug("类"+className+"方法"+methodName+"消耗了"+m+"ms");
		return obj;
	}
	
}